package com.bdqn.service;

import com.bdqn.common.PageSupport;
import com.bdqn.mapper.SysUserMapper;
import com.bdqn.pojo.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* SysUserService服务层实现类
*/
@Service("sysUserService")
public class SysUserServiceImpl implements SysUserService {

    @Resource // 使用注解的方式将DAO层的Bean注入
    private SysUserMapper sysUserMapper;

    /**
     * 根据用户登录账号获取用户信息
     *
     * @param account 账号
     * @param password 密码
     * @return
     */
    @Override
    public SysUser getSysUserByAccount(String account, String password) {
        if (account == null || password == null) {
            return null;
        }
        return sysUserMapper.getByAccountAndPassword(account, password);
    }



    /**
     * 保存用户
     *
     * @param sysUser
     * @return
     */
    @Override
    public boolean add(SysUser sysUser) {
        return sysUserMapper.add(sysUser) == 1;
    }

    @Override
    public List<SysUser> getPageList(SysUser sysUser, PageSupport page) {
        return sysUserMapper.getPageList(sysUser, (page.getCurrentPageNo() - 1) * page.getPageSize(), page.getPageSize());

    }

    /**
     * 根据条件获得总记录数
     *
     * @param sysUser
     * @return
     */
    @Override
    public int getPageListTotal(SysUser sysUser) {
        return sysUserMapper.getPageListTotal(sysUser);
    }


    @Override
    public List<SysUser> getList(SysUser sysUser) {
        return sysUserMapper.getList(sysUser);
    }

    @Override
    public SysUser getById(long id) {
        return sysUserMapper.getById(id);
    }

    @Override
    public  boolean del(long id) {
        return sysUserMapper.delete(id)==1;
    }

    @Override
    public boolean update(SysUser sysUser) {
        sysUser.setUpdatedTime(new Date()); // 设置修改时间
        return sysUserMapper.update(sysUser);
    }


}
